﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace awsomeSyntezator.PipeLine.Oscilators
{
	class TRIwawe : Oscilator
    {
		public double step;
		public bool sign;
		public double previous;
		private double current;

        public TRIwawe(float _freq, int _rate, int strenght): base(_freq, _rate, strenght)
        {
            type = 0;
			double n1 = (Math.Asin(1.0) * Options.rate) / (2.0 *Math.PI*frequency);
			double n2 = (Math.Asin(-1.0) * Options.rate) / (2.0 * Math.PI * frequency);
        	step = 2.0/(Math.Max(n1,n2) - Math.Min(n1,n2));
        	sign = true;
			previous = 0;
        }
        public override double getSample(int n, double sample)
        {
			if (previous >= 1.0 - step)
				sign = false;
			if (previous <= -1.0 + step)
				sign = true;
			if (sign)
				current = previous + step;
			else
				current = previous - step; 
 
        	previous = current;
        	return current;

        }
	}
}
